package org.transfer.utils;

import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LogUtils {

	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	/**
	 * 打印日志
	 * 
	 * @param path
	 * @param append
	 */
	public static void log(String path, String message) {
		FileWriter fw = null;
		try {
			fw = new FileWriter(path);
			fw.write(sdf.format(new Date()) + ":" + message);
			fw.write("\n");
			fw.close();
		} catch (IOException e) {
			if (fw != null) {
				try {
					fw.close();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
			e.printStackTrace();
		}
	}

	/**
	 * 打印日志
	 * 
	 * @param path
	 * @param append
	 */
	public static void logs(String path, String message) {
		FileWriter fw = null;
		try {
			fw = new FileWriter(path, true);
			fw.write(sdf.format(new Date()) + ":" + message);
			fw.write("\n");
			fw.close();
		} catch (IOException e) {
			if (fw != null) {
				try {
					fw.close();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
			e.printStackTrace();
		}
	}

}
